<?php
declare(strict_types=1);

namespace Modules\Production\Http\Controllers;

use Catch\Base\CatchController as Controller;
use Modules\Production\Models\MaterialReturnPlanOrder;
use Illuminate\Http\Request;use Modules\Production\Repository\MaterialReturnPlanOrderrRepository;


class MaterialReturnPlanOrderController extends Controller
{
    public function __construct(
        protected readonly MaterialReturnPlanOrder $model
    ){}

    /**
     * @param Request $request
     * @return mixed
     */
    public function index(): mixed
    {
        return $this->model->getList();
    }

    /**
     * 生产退料计划提交
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        return MaterialReturnPlanOrderrRepository::storeBy($request->post());
    }

    /**
     * 生产退料计划修改提交
     * @param Request $request
     * @return bool
     * @throws Exception
     */
    public function modify(Request $request){
        return MaterialReturnPlanOrderrRepository::modifySubmit($request->post());
    }

    /**
     * 生产退料计划箱号扫描
     * @param Request $request
     */
    public function scan(Request $request){
        return MaterialReturnPlanOrderrRepository::scanBy($request->get('lot_num'));
    }

    /**
     * @param $id
     * @return mixed
     */
    public function show($id)
    {
        return $this->model->firstBy($id);
    }

    /**
     * @param Request $request
     * @param $id
     * @return mixed
     */
    public function update($id, Request $request)
    {
        return $this->model->updateBy($id, $request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->model->deleteBy($id);
    }

    /**
     * 根据箱号查询所有退料计划单
     * @param Request $request
     */
    public function getByLotNum(Request $request){
        return MaterialReturnPlanOrderrRepository::getOrderDetailByLotnum($request->get('lot_num'));
    }
}
